<template>
	<u-count-down :time="time" format="DD:HH:mm:ss" autoStart millisecond @change="onChangeCountdown" @finish="$emit('finish')">
		<view class="time">
			<template v-if="timeData.days>0">
				<view class="time__custom" :style="[backgroundStyle]">
					<text class="time__custom__item" :style="[txtStyle]">{{ timeData.days }}天</text>
				</view>
				<text class="time__doc" :style="[dotStyle]">:</text>
			</template>
			<view class="time__custom" :style="[backgroundStyle]">
				<text class="time__custom__item"
					:style="[txtStyle]">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}</text>
			</view>
			<text class="time__doc" :style="[dotStyle]">:</text>
			<view class="time__custom" :style="[backgroundStyle]">
				<text class="time__custom__item" :style="[txtStyle]">{{ timeData.minutes }}</text>
			</view>
			<text class="time__doc" :style="[dotStyle]">:</text>
			<view class="time__custom" :style="[backgroundStyle]">
				<text class="time__custom__item" :style="[txtStyle]">{{ timeData.seconds }}</text>
			</view>
		</view>
	</u-count-down>
</template>

<script>
	export default {
		props: {
			color: {
				type: String,
				default: '#FE0000'
			},
			time: {
				type: String | Number,
				default: null
			}
		},
		data() {
			return {
				timeData: {},
			}
		},
		computed: {
			backgroundStyle() {
				return {
					backgroundColor: this.color,
					...(this.color === '#fff' || this.color === '#ffffff') ? {
						border: '2rpx solid #E0E0E0',
						color: '#333'
					} : {}
				}
			},
			dotStyle() {
				return {
					color: (this.color === '#fff' || this.color === '#ffffff') ? '#333' : this.color,
				}
			},
			txtStyle() {
				return {
					...(this.color === '#fff' || this.color === '#ffffff') ? {
						color: '#333'
					} : {}
					
				}
			},
		},
		methods: {
			onChangeCountdown(e) {
				this.timeData = e
			}
		},
	}
</script>

<style lang="scss">
	.time {
		@include flex;
		align-items: center;

		&__custom {
			margin-top: 8rpx;
			width: 32rpx;
			height: 36rpx;
			background-color: #8F5705;
			border-radius: 8rpx;
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			justify-content: center;
			align-items: center;

			&__item {
				color: #fff;
				font-size: 20rpx;
				text-align: center;
			}
		}

		&__doc {
			color: #8F5705;
			padding: 0px 4rpx;
		}

		&__item {
			color: #606266;
			font-size: 20rpx;
			margin-right: 8rpx;
		}
	}

	.time__custom {
		margin-top: 0 !important;
	}
</style>